package com.summer.safe.system.entity;


import com.google.common.collect.Lists;
import com.summer.safe.base.BaseEntity;

import java.util.Date;
import java.util.List;

/**
 * 用户Entity
 *
 */
public class User extends BaseEntity<User> {
    private static final long serialVersionUID = 1L;


    /**
     * 归属部门
     */
    private Office office;

    /**
     * 登录名
     */
    private String loginName;
    /**
     * 密码
     */
    private String password;
    /**
     * 姓名
     */
    private String name;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 电话
     */
    private String phone;
    /**
     * 手机
     */
    private String mobile;
    /**
     * 用户类型
     */
    private String userType;
    /**
     * 最后登陆IP
     */
    private String loginIp;
    /**
     * 最后登陆日期
     */
    private Date loginDate;
    /**
     * 是否允许登陆
     */
    private String loginFlag;
    /**
     * 头像
     */
    private String photo;
    /**
     * 职务
     */
    private String job;
    /**
     * 原登录名
     */
    private String oldLoginName;
    /**
     * 新密码
     */
    private String newPassword;
    /**
     * 上次登陆IP
     */
    private String oldLoginIp;
    /**
     * 上次登陆日期
     */
    private Date oldLoginDate;
    /**
     * 根据角色查询用户条件
     */
    private Role role;
    
    /**
     * 拥有角色列表
     */
    private List<Role> roleList;

    /**
     * 注册标记，用于标记通过注册来的用户
     */
    private String registerFlag;


    /**
     * 签名
     */
    private String sign;

    public String status;


    /*用户类型，系统管理员*/
    public static final String ADMIN = "0";
    /*用户类型，政府*/
    public static final String GOV = "1";
    /*用户类型，企业*/
    public static final String ENTER = "4";
    /*用户类型，公众*/
    public static final String PUBLIC = "5";


    public User() {
        super();
        this.loginFlag = "1";
    }

    public User(String id) {
        super(id);
    }

    public User(String id, String loginName) {
        super(id);
        this.loginName = loginName;
    }

    public User(Role role) {
        super();
        this.role = role;
    }


    public Office getOffice() {
        return office;
    }

    public void setOffice(Office office) {
        this.office = office;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getLoginIp() {
        return loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    public Date getLoginDate() {
        return loginDate;
    }

    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    }

    public String getLoginFlag() {
        return loginFlag;
    }

    public void setLoginFlag(String loginFlag) {
        this.loginFlag = loginFlag;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public String getOldLoginName() {
        return oldLoginName;
    }

    public void setOldLoginName(String oldLoginName) {
        this.oldLoginName = oldLoginName;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }

    public String getOldLoginIp() {
        return oldLoginIp;
    }

    public void setOldLoginIp(String oldLoginIp) {
        this.oldLoginIp = oldLoginIp;
    }

    public Date getOldLoginDate() {
        return oldLoginDate;
    }

    public void setOldLoginDate(Date oldLoginDate) {
        this.oldLoginDate = oldLoginDate;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }



    public String getRegisterFlag() {
        return registerFlag;
    }

    public void setRegisterFlag(String registerFlag) {
        this.registerFlag = registerFlag;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<Role> getRoleList() {
        return roleList;
    }

    public List<String> getRoleIdList() {
        List<String> roleIdList = Lists.newArrayList();
        if(roleList != null){
            for (Role role : roleList) {
                roleIdList.add(role.getId());
            }
        }
        return roleIdList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    public boolean isAdmin() {
        return isAdmin(this.id);
    }

    public static boolean isAdmin(String id) {
        return id != null && "1".equals(id);
    }
}
